package parser

import (
	"01-crawler-project/01/engine"
	"net/http"
	"regexp"
)

var regex_a_group_a = `<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)"[^>]*>([\p{Han}]+)</a>`

func ParserCityList(contents [] byte) engine.ParserResult {

	compile := regexp.MustCompile(regex_a_group_a)

	cityLists := compile.FindAllSubmatch(contents, -1)

	result := engine.ParserResult{}

	for _, v := range cityLists {

		//城市
		result.Items = append(result.Items, string(v[2]))

		HttpRequest, _ := http.NewRequest(http.MethodGet, string(v[1]), nil)

		result.Requests = append(result.Requests, engine.Request{HttpRequest, ParseCityUserInfo})
	}

	return result

}
